#pragma once
#define RUNTIME_DBG_LVL 0
#define SYS_LOCKTEST(lockname)\
do{\
	lockname##lock_t __p;\
	lock_t *__l = lockname##_init(&__p, sizeof(lockname##lock_t));\
	assert(lockname##_slock(__l));\
	printf("in " #lockname " critical section\n");\
	assert(lockname##_sunlock(__l));\
}while(0)

#define SIMPLE_LOCKTEST_RELAX(lockname)\
do{\
	lockname##lock_t __p;\
	lock_t *__l = lockname##_init(&__p, sizeof(lockname##lock_t));\
	locktoken_t tk = (void *)0;\
	assert(lockname##_lock_relax(__l, &tk));\
	printf("in " #lockname " critical section\n");\
	assert(lockname##_unlock_relax(__l, tk));\
}while(0)

#define SIMPLE_LOCKTEST(lockname)\
do{\
	lockname##lock_t __p;\
	lock_t *__l = lockname##_init(&__p, sizeof(lockname##lock_t));\
	locktoken_t tk = (void *)0;\
	assert(lockname##_lock(__l, &tk));\
	printf("in " #lockname " critical section\n");\
	assert(lockname##_unlock(__l, tk));\
}while(0)

#define TIMEOUT_LOCKTEST(lockname)\
do{\
	lockname##lock_t __p;\
	lock_t *__l = lockname##_init(&__p, sizeof(lockname##lock_t));\
	locktoken_t tk = (void *)0;\
	assert(lockname##_lock(__l, &tk));\
	assert(!lockname##_timed_lock(__l, &tk, 1000));\
	printf("success timeout in " #lockname " critical section\n");\
	assert(lockname##_timed_unlock(__l, tk, 1000));\
}while(0)

#define SIMPLE_COMBINETEST(cmbnname, critsec_func, arg)\
	({\
	cmbnname##_t __p;\
	apds_t *__l = cmbnname##_init(&__p, sizeof(cmbnname##_t));\
	assert(__l != NULL);					\
	apdsret_t ret = cmbnname##_sync(__l, critsec_func, arg);\
	ret; })


